<template>
  <view class="app-popup-background" v-show="popupShow" :class="[popupShow ? 'popup-show' : 'popuphide']"
    catchtouchmove="ture">
    <view class="app-popup-rbga" @click.stop="close"></view>
    <view class="app-popup" :style="[{ height: height ? height + '%' : 'auto', zIndex: zIndex }]">
      <view class="app-popup-top">
        <view v-if="title" class="app-popup-title">{{ title }}</view>
        <uni-icons  @click.stop="close" type="closeempty" class="app-popup-turnoff" size="30"></uni-icons>
      </view>
      <scroll-view v-if="sliding" scroll-y="true" class="app-popup-view">
        <slot></slot>
      </scroll-view>
      <view v-else class="app-popup-view">
        <slot></slot>
      </view>
    </view>
  </view>
</template>

<script>
import { stitchingURL } from "@/common/util.js";
export default {
  name: "popup",
  props: {
    title: [Number, String],
    popupShow: {
      type: Boolean,
      default: false,
    },
    tipShow: {
      type: Boolean,
      default: false,
    },
    secondaryShow: {
      type: Boolean,
      default: false,
    },
    sliding: {
      type: Boolean,
      default: true,
    },
    height: {
      type: Number,
      default: null,
    },
    zIndex: {
      type: Number,
      default: 99999,
    },
  },
  computed: {
    imageURL() {
      return (name, type) => {
        return stitchingURL(name, type);
      };
    },
  },
  data() {
    return {};
  },
  methods: {
    close() {
      // 关闭popup
      this.$emit("popupHidden");
    },
  },
};
</script>

<style lang="scss">
@keyframes hide {
  0% {
    transform: translateY(0);
  }

  100% {
    transform: translateY(100%);
  }
}

@keyframes show {
  0% {
    transform: translateY(100%);
  }

  100% {
    transform: translateY(0);
  }
}

.app-popup-background {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 999;

  &.min-hide {
    .popup-popup {
      animation: hide 0.1s linear forwards;
    }

    .app-popup-turnoff {
      opacity: 0;
    }
  }

  &.popup-show {
    .app-popup {
      animation: show 0.1s linear forwards;
    }

    .app-popup-turnoff {
      opacity: 1;
    }
  }

  .app-popup-rbga {
    position: absolute;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    z-index: 11;
    background: rgba(0, 0, 0, 0.5);
    z-index: 9999;
  }

  .app-popup {
    width: 100%;
    background: #ffffff;
    position: absolute;
    bottom: 0;
    left: 0;
    height: auto;
    overflow: hidden;
    z-index: 111;
    border-radius: 18upx 18upx 0upx 0upx;
    transform: translate3d(0, 100%, 0);

    .app-popup-top {
      height: 154upx;
      width: 100%;
      padding-top: 46upx;
      position: relative;

      .app-popup-title {
        color: #3a3a3a;
        font-size: 34upx;
        font-weight: bold;
        line-height: 53upx;
        text-align: center;
      }

      .app-popup-turnoff {
        width: 66rpx;
        height: 66rpx;
        padding: 20rpx;
        position: absolute;
        right: 0;
        top: 0;
        z-index: 111;
      }

      .app-popup-secondary-title {
        position: absolute;
        bottom: 0;
        left: 0;
        height: 50upx;
        width: 100%;
        background: #fbfbfc;
        line-height: 50upx;
        text-align: center;
        font-size: 26upx;
        color: #9b9b9b;
        z-index: 111;
      }
    }

    .app-popup-view {
      position: absolute;
      top: 154rpx;
      bottom: 30upx;
      left: 0;
      right: 0;
      -webkit-overflow-scrolling: touch;
    }

  }
}
</style>
